# errors 错误封装

from fastapi import FastAPI
from fastapi.exceptions import RequestValidationError

from .http_error import httpExceptionHandler
from .validation_error import validationExceptionHandler
from .app_error import appExceptionHandler

from starlette.exceptions import HTTPException as StarletteHTTPException


def registerCustomErrorHandle(server: FastAPI):
    """统一注册自定义错误处理器"""
    # 注册参数验证错误，并覆盖模式 RequestValidationError
    server.add_exception_handler(RequestValidationError,validationExceptionHandler)
    # 错误处理 starletteHTTPException
    server.add_exception_handler(StarletteHTTPException,httpExceptionHandler)
    # 自定义全局系统错误
    server.add_exception_handler(Exception, appExceptionHandler)
